﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Entity;
using System.IO;


namespace App.Store
{
    public partial class frmSample : Form
    {
        

        Entities db = new Entities();

        T_Sample m_Sample = null;

        private int id = 0;

        public int m_xID 
        {
            get { return id; }
            set { id = value; }
        }
        public string m_bowplateProductNo { get; set; }
        public string m_originalshoeProductNo { get; set; }
        public string m_soleProductNo { get; set; }

        private bool IsQuery = true;
        private bool bIsAdd = false;

        //样鞋
        public int xID
        {
            set
            {
                var samplelist = db.T_Sample.Where(a => a.xID == value);
                foreach (T_Sample sample in samplelist)
                {
                    m_Sample = sample;
                    break;
                }
                if (m_Sample == null) return;

                txtColorCode.Text = m_Sample.colorCode;
                txtShoeName.Text = m_Sample.sName;
                txtShoeColor.Text = m_Sample.color;
                cbYard.Text = m_Sample.yard;
                cbShoesize1.Text = m_Sample.size1;
                txtShoesize2.Text = m_Sample.size2;
                txtXc.Text = m_Sample.xc;
                cbYard1.Text = m_Sample.yard1;
                cbYard2.Text = m_Sample.yard2;
                cbYard3.Text = m_Sample.yard3;
                cbYard4.Text = m_Sample.yard4;
                cbPacking.Text = m_Sample.packing;
                txtInsoleBoard.Text = m_Sample.InsoleBoard;
                cbch1.Text = m_Sample.ch1;
                cbch2.Text = m_Sample.ch2;
                cbch3.Text = m_Sample.ch3;
                txtchValue1.Text = m_Sample.chValue1;
                txtchValue2.Text = m_Sample.chValue2;
                txtchValue3.Text = m_Sample.chValue3;
                txtShoeProductNo.Text = m_Sample.productNo;
                cbCust.Text = m_Sample.cust;
                cbBrand.Text = m_Sample.brand;
                cbCustDept.Text = m_Sample.custDept;
                txtOrderNo.Text = m_Sample.orderNo;
                txtcustProductNo.Text = m_Sample.custProductNo;
                cbBuyer.Text = m_Sample.buyer;
                cbFactory.Text = m_Sample.factory;
                txtFactNo.Text = m_Sample.factNo;
                txtXtNo.Text = m_Sample.xtNo;
                cbSiMo.Text = m_Sample.SiMo;
                txtDesignNo.Text = m_Sample.designNo;
                txtPrice1.Text = m_Sample.price1.ToString();
                txtPrice2.Text = m_Sample.price2.ToString();
                txtPrice3.Text = m_Sample.price3.ToString();
                txtPrice4.Text = m_Sample.price4.ToString();
                txtdPrice1.Text = m_Sample.dPrice1.ToString();
                txtdPrice2.Text = m_Sample.dPrice2.ToString();
                txtdPrice3.Text = m_Sample.dPrice3.ToString();
                txtdPrice4.Text = m_Sample.dPrice4.ToString();
                txtCounter.Text = m_Sample.Counter;

                if (m_Sample.bCanPrint == true) ckbCanPrint.Checked = true;
                if (m_Sample.IBS == "是") ckIBS.Checked = true;
                if (m_Sample.PML == "是") ckPML.Checked = true;
                if (m_Sample.PT3 == "是") ckPT3.Checked = true;

                cbProperty.Text = m_Sample.property;
                txtSampleNo.Text = m_Sample.SampleNo;
                txtSeason.Text = m_Sample.seasonType;
                txtbmStruct.Text = m_Sample.bmStruct;
                txtbmMaterial.Text = m_Sample.bmMaterial;
                cblMaterial.Text = m_Sample.lMaterial;
                cbSoleFactory.Text = m_Sample.SoleFactory;
                txtsoleYard.Text = m_Sample.soleYard;
                txtnewXtNo.Text = m_Sample.newXtNo;
                txtsoleNo.Text = m_Sample.soleNo;
                cbsoleMaterial.Text = m_Sample.soleMaterial;
                txtallCount.Text = m_Sample.allCount.ToString();
                txtpCount.Text = m_Sample.pCount.ToString();
                txtprintedCount.Text = m_Sample.printedCount.ToString();
                txtLocation.Text = m_Sample.location;
                dtopDate.Text = m_Sample.opDate.ToString();
                txtRemark.Text = m_Sample.reMark;
                txtpMgr.Text = m_Sample.pMgr;
                txtInsock.Text = m_Sample.insock;
                txtPort.Text = m_Sample.port;
                cbsGroup.Text = m_Sample.sGroup;


            }
        }

        //船头板
        public int BowplateProduct
        {
            set
            {
                var bowplatelist = db.T_Sample.Where(a => a.xID == value);
                foreach (T_Sample sample in bowplatelist)
                {
                    m_Sample = sample;
                    break;
                }

                if (m_Sample == null) return;
                txtBowProductNo.Text = m_Sample.productNo;
                txtBowallCount.Text = m_Sample.allCount.ToString();
                txtbowcolor.Text = m_Sample.color;
                txtBowCust.Text = m_Sample.cust;
                txtBowlocation.Text = m_Sample.location;
                txtBoworderNo.Text = m_Sample.orderNo;
                txtBowpCount.Text = m_Sample.pCount.ToString();
                txtBowRemark.Text = m_Sample.reMark;
                txtBowsize2.Text = m_Sample.size2;
                txtbowsName.Text = m_Sample.sName;
                cbBowBrand.Text = m_Sample.brand;
                cbBowFactory.Text = m_Sample.factory;
                cbBowsize1.Text = m_Sample.size1;
                cbBowYard.Text = m_Sample.yard;
                dtbowDate.Text = m_Sample.opDate.ToString();
                txtfinalCust.Text = m_Sample.custDept;
                txtCProductNo.Text = m_Sample.custProductNo;
                txtcontractNo.Text = m_Sample.contractNo;
            }
        }

        //原版鞋
        public int OriginalShoeProductNo
        {
            set
            {
                var originalShoelist = db.T_Sample.Where(a => a.xID == value);
                foreach (T_Sample sample in originalShoelist)
                {
                    m_Sample = sample;
                    break;
                }
                if (m_Sample == null) return;

                txtOallCount.Text = m_Sample.allCount.ToString();
                txtOCProductNo.Text = m_Sample.custProductNo;
                txtOCust.Text = m_Sample.cust;
                txtOLocation.Text = m_Sample.location;
                txtOpCount.Text = m_Sample.pCount.ToString();
                txtOProductNo.Text = m_Sample.productNo;
                txtOProviderDept.Text = m_Sample.providerDept;
                txtORemark.Text = m_Sample.reMark;
                cbOBrand.Text = m_Sample.brand;
                cbOProvider.Text = m_Sample.prodiver;
                dtOopDate.Text = m_Sample.opDate.ToString();
                
                
            }
        }

        //大底
        public int SoleProductNo
        {
            set
            {
                var solelist = db.T_Sample.Where(a => a.xID == value);
                foreach (T_Sample sample in solelist)
                {
                    m_Sample = sample;
                    break;
                }
                if (m_Sample == null) return;

                txtSallCount.Text = m_Sample.allCount.ToString();
                txtSfactNo.Text = m_Sample.factNo;
                txtSLocation.Text = m_Sample.location;
                txtSpCount.Text = m_Sample.pCount.ToString();
                txtSPrice1.Text = m_Sample.price1.ToString();
                txtSPrice2.Text = m_Sample.price2.ToString();
                txtSPrice3.Text = m_Sample.price3.ToString();
                txtSPrice4.Text = m_Sample.price4.ToString();
                txtSProductNo.Text = m_Sample.productNo;
                txtSRemark.Text = m_Sample.reMark;
                txtSSize2.Text = m_Sample.size2;
                txtSSoleNo.Text = m_Sample.soleNo;
                txtSSType.Text = m_Sample.sType;
                txtSYard.Text = m_Sample.yard;
                txtSYard1.Text = m_Sample.yard1;
                txtSYard2.Text = m_Sample.yard2;
                txtSYard3.Text = m_Sample.yard3;
                txtSYard4.Text = m_Sample.yard4;
                cbSFactory.Text = m_Sample.factory;
                cbSSoleMaterial.Text = m_Sample.soleMaterial;
                dtSDate.Text = m_Sample.opDate.ToString();
                if (m_Sample.bCanPrint == true) ckSbCanPrint.Checked = true;
            }
        }


        public frmSample()
        {
            InitializeComponent();
            
            //gv2DataSource();
            //gv3DataSource();
            //gv4DataSource();
        }

      

        private void rbGroup_CheckedChanged(object sender, EventArgs e)
        {
            if (rbShoesSample.Checked)
            {
                //gv1.Visible = true;
                //gv2.Visible = false;
                //gv3.Visible = false;
                //gv4.Visible = false;
                gv1.DataSource = bs1;

                cTabs1.SelectTab(tabShoeSample);
                bNav.BindingSource = bs1;
            }
            else if (rbBowPlate.Checked)
            {
                //gv1.Visible = false;
                //gv2.Visible = true;
                //gv3.Visible = false;
                //gv4.Visible = false;
                gv1.DataSource = bs2;

                cTabs1.SelectTab(tabBowPlate);
                bNav.BindingSource = bs2;
            }
            else if (rbOriginalShoe.Checked)
            {
                //gv1.Visible = false;
                //gv2.Visible = false;
                //gv3.Visible = true;
                //gv4.Visible = false;
                gv1.DataSource = bs3;

                cTabs1.SelectTab(tabOriginShoe);
                bNav.BindingSource = bs3;
            }
            else if (rbSole.Checked)
            {
                //gv1.Visible = false;
                //gv2.Visible = false;
                //gv3.Visible = false;
                //gv4.Visible = true;
                gv1.DataSource = bs4;

                cTabs1.SelectTab(tabSole);
                bNav.BindingSource = bs4;
            }
        }

        private void btn1_Click(object sender, EventArgs e)
        {
            gvID();
            if (this.IsQuery)
            {
                this.panDetail.BringToFront();
                this.btn1.Text = "概要";
                this.IsQuery = false;
                //if (rbShoesSample.Checked)
                //{
                //    cTabs1.SelectTab(tabShoeSample);
                //}
                //else if (rbBowPlate.Checked)
                //{
                //    cTabs1.SelectTab(tabBowPlate);
                //}
                //else if (rbOriginalShoe.Checked)
                //{
                //    cTabs1.SelectTab(tabOriginShoe);
                //}
                //else if (rbSole.Checked)
                //{
                //    cTabs1.SelectTab(tabSole);
                //}
            }
            else
            {
                this.panList.BringToFront();
                this.btn1.Text = "明细";
                this.IsQuery = true;

                if (cTabs1.SelectedTab == tabShoeSample)
                {
                    rbShoesSample.Checked = true;
                }
                else if(cTabs1.SelectedTab == tabBowPlate)
                {
                    rbBowPlate.Checked = true;
                }
                else if (cTabs1.SelectedTab == tabOriginShoe)
                {
                    rbOriginalShoe.Checked = true;
                }
                else if (cTabs1.SelectedTab == tabSole)
                {
                    rbSole.Checked = true;
                }
            }
        }

        private void gv1DataSource()
        {
            //样鞋绑定
            DateTime today=DateTime.Now.Date;
            if (rbShoesSample.Checked)
            {
                var gv1list = db.T_Sample.Where(a => a.opDate == today && a.sKind == "鞋样").ToList();
                bs1.DataSource = gv1list;
                bNav.BindingSource = bs1;
            }
            if (rbBowPlate.Checked)
            {
                //船头板绑定
                //DateTime today = DateTime.Now.Date;
                var gv2list = db.T_Sample.Where(a => a.opDate == today && a.sKind == "船头板").ToList();
                bs2.DataSource = gv2list;
                bNav.BindingSource = bs2;
            }

            if (rbOriginalShoe.Checked)
            {
                //原版鞋绑定
                //DateTime today = DateTime.Now.Date;
                var gv3list = db.T_Sample.Where(a => a.opDate == today && a.sKind == "原版鞋").ToList();
                bs3.DataSource = gv3list;
                bNav.BindingSource = bs3;
            }
            if (rbSole.Checked)
            {
                //大底绑定
                //DateTime today = DateTime.Now.Date;
                var gv4list = db.T_Sample.Where(a => a.opDate == today && a.sKind == "大底").ToList();
                bs4.DataSource = gv4list;
                bNav.BindingSource = bs4;
            }
        }

        private void gv2DataSource()
        {
            //船头板绑定
            DateTime today = DateTime.Now.Date;
            var gv2list = db.T_Sample.Where(a => a.opDate == today && a.sKind == "船头板").ToList();
            bs2.DataSource = gv2list;
        }

        private void gv3DataSource()
        {
            //原版鞋绑定
            DateTime today = DateTime.Now.Date;
            var gv3list = db.T_Sample.Where(a => a.opDate == today && a.sKind == "原版鞋").ToList();
            bs3.DataSource = gv3list;
        }

        private void gv4DataSource()
        {
            //大底绑定
            DateTime today = DateTime.Now.Date;
            var gv4list = db.T_Sample.Where(a => a.opDate == today && a.sKind == "大底").ToList();
            bs4.DataSource = gv4list;
        }

        private void GetBaseInfo()
        {
            //码段
            Service.Yard(cbYard);

            //码制
            Service.Size2(cbShoesize1);

            //化学物质
            Service.Chymist(cbch1);

            //化学物质
            Service.Chymist(cbch2);

            //化学物质
            Service.Chymist(cbch3);

            //客户
            Service.Cust(cbCust);

            //品牌
            Service.Brand(cbBrand);

            //最终客户
            Service.CustDept(cbCustDept);

            //业务员
            Service.Buyer(cbBuyer);

            //工厂
            Service.Factory(cbFactory);

            //样品性质
            Service.Property(cbProperty);

            //内里材料
            Service.lMaterial(cblMaterial);

            //帮面材料
            var list = db.T_MaterialDesc.Where(a => a.materialType == "帮面").Select(a=>a.materialEN).ToList();
            txtbmMaterial.Data = list;

            //大底底厂
            Service.SoleFactory(cbSoleFactory);

            //大底材料
            Service.SoleMaterial(cbsoleMaterial);

            //组
            Service.Group(cbsGroup);

            //船头板
            //码段
            Service.Yard(cbBowYard);

            //码制
            Service.Size2(cbBowsize1);

            //品牌
            Service.Brand(cbBowBrand);

            Service.Factory(cbBowFactory);

            //原版鞋
            //原版鞋品牌

            //提供者


            //大底
            //工厂
            Service.Factory(cbSFactory);

            //大底材料
            Service.SoleMaterial(cbSSoleMaterial);

            //查询
            // 品牌
            Service.Brand(txtSelBrand);

            //工厂
            Service.Factory(txtSelFactory);

            //库存位置
            Service.Location(txtSelLocation);
        }

        private void gvID()
        {
            if (gv1.RowCount > 0)
            {
                int index = gv1.CurrentRow.Index;    //取得选中行的索引  
                this.m_xID = Convert.ToInt32(gv1.Rows[index].Cells["colxID"].Value.ToString());
                this.xID = Convert.ToInt32(gv1.Rows[index].Cells["colxID"].Value.ToString());
            }
            else
            {
                TxtSampleClear();
            }
            //if (rbShoesSample.Checked)
            //{
            //    if (gv1.RowCount > 0)
            //    {
            //        int index = gv1.CurrentRow.Index;    //取得选中行的索引  
            //        this.m_sampleProductNo = gv1.Rows[index].Cells["colProductNo"].Value.ToString();
            //        this.SampleProductNo = gv1.Rows[index].Cells["colProductNo"].Value.ToString();
            //    }
            //    else
            //    {
            //        TxtSampleClear();
            //    }
            //}
            //else if (rbBowPlate.Checked)
            //{
            //    if (gv2.RowCount > 0)
            //    {
            //        int index = gv2.CurrentRow.Index;    //取得选中行的索引  
            //        this.m_bowplateProductNo = gv2.Rows[index].Cells["colBowProductNo"].Value.ToString();
            //        this.BowplateProduct = gv2.Rows[index].Cells["colBowProductNo"].Value.ToString();
            //    }
            //    else
            //    {
            //        TxtBowplateClear();
            //    }
            //}
            //else if (rbOriginalShoe.Checked)
            //{
            //    if (gv3.RowCount > 0)
            //    {
            //        int index = gv3.CurrentRow.Index;    //取得选中行的索引  
            //        this.m_originalshoeProductNo = gv3.Rows[index].Cells["colOProductNo"].Value.ToString();
            //        this.OriginalShoeProductNo = gv3.Rows[index].Cells["colOProductNo"].Value.ToString();
            //    }
            //    else
            //    {
            //        TxtOriginalClear();
            //    }
            //}
            //else if (rbSole.Checked)
            //{
            //    if (gv4.RowCount > 0)
            //    {
            //        int index = gv4.CurrentRow.Index;    //取得选中行的索引  
            //        this.m_soleProductNo = gv4.Rows[index].Cells["colSProductNo"].Value.ToString();
            //        this.SoleProductNo = gv4.Rows[index].Cells["colSProductNo"].Value.ToString();
            //    }
            //    else
            //    {
            //        TxtSoleClear();
            //    }
            //}
        }


        //鞋样增加
        private void SaveAdd()
        {
            m_Sample = new T_Sample();
            if (db.T_Sample.Count() <= 0) m_Sample.xID = 1;
            else m_Sample.xID = db.T_Sample.OrderByDescending(a => a.xID).First().xID + 1;
            m_Sample.colorCode=txtColorCode.Text;
            m_Sample.sName=txtShoeName.Text;
            m_Sample.color=txtShoeColor.Text;
            m_Sample.yard=cbYard.Text;
            m_Sample.size1=cbShoesize1.Text;
            m_Sample.size2=txtShoesize2.Text;
            m_Sample.xc=txtXc.Text;
            m_Sample.yard1=cbYard1.Text;
            m_Sample.yard2=cbYard2.Text ;
            m_Sample.yard3=cbYard3.Text;
            m_Sample.yard4=cbYard4.Text;
            m_Sample.packing=cbPacking.Text;
            m_Sample.InsoleBoard=txtInsoleBoard.Text;
            m_Sample.ch1=cbch1.Text;
            m_Sample.ch2=cbch2.Text;
            m_Sample.ch3=cbch3.Text;
            m_Sample.chValue1=txtchValue1.Text;
            m_Sample.chValue2=txtchValue2.Text;
            m_Sample.chValue3=txtchValue3.Text ;
            m_Sample.productNo=txtShoeProductNo.Text;
            m_Sample.cust=cbCust.Text;
            m_Sample.brand=cbBrand.Text;
            m_Sample.custDept=cbCustDept.Text;
            m_Sample.orderNo=txtOrderNo.Text;
            m_Sample.custProductNo=txtcustProductNo.Text;
            m_Sample.buyer=cbBuyer.Text;
            m_Sample.factory=cbFactory.Text;
            m_Sample.factNo=txtFactNo.Text;
            m_Sample.xtNo=txtXtNo.Text;
            m_Sample.SiMo=cbSiMo.Text;
            m_Sample.designNo=txtDesignNo.Text;
            if (!string.IsNullOrEmpty(txtPrice1.Text.Trim())) m_Sample.price1=Convert.ToInt32( txtPrice1.Text);
            if (!string.IsNullOrEmpty(txtPrice2.Text.Trim())) m_Sample.price2 = Convert.ToInt32(txtPrice2.Text);
            if (!string.IsNullOrEmpty(txtPrice3.Text.Trim())) m_Sample.price3 = Convert.ToInt32(txtPrice3.Text);
            if (!string.IsNullOrEmpty(txtPrice4.Text.Trim())) m_Sample.price4 = Convert.ToInt32(txtPrice4.Text);
            if (!string.IsNullOrEmpty(txtdPrice1.Text.Trim())) m_Sample.dPrice1=Convert.ToInt32( txtdPrice1.Text);
            if (!string.IsNullOrEmpty(txtdPrice2.Text.Trim())) m_Sample.dPrice2 = Convert.ToInt32(txtdPrice2.Text);
            if (!string.IsNullOrEmpty(txtdPrice3.Text.Trim())) m_Sample.dPrice3 = Convert.ToInt32(txtdPrice3.Text);
            if (!string.IsNullOrEmpty(txtdPrice4.Text.Trim())) m_Sample.dPrice4 = Convert.ToInt32(txtdPrice4.Text);
            m_Sample.Counter=txtCounter.Text;

            if (ckbCanPrint.Checked) m_Sample.bCanPrint = true;
            if (ckIBS.Checked) m_Sample.IBS = "是";
            if (ckPML.Checked) m_Sample.PML = "是";
            if (ckPT3.Checked) m_Sample.PT3 = "是";

            m_Sample.property = cbProperty.Text;
            m_Sample.SampleNo = txtSampleNo.Text;
            m_Sample.seasonType = txtSeason.Text;
            m_Sample.bmStruct=txtbmStruct.Text;
            m_Sample.bmMaterial=txtbmMaterial.Text;
            m_Sample.lMaterial=cblMaterial.Text;
            m_Sample.SoleFactory=cbSoleFactory.Text;
            m_Sample.soleYard=txtsoleYard.Text ;
            m_Sample.newXtNo=txtnewXtNo.Text;
            m_Sample.soleNo=txtsoleNo.Text ;
            m_Sample.soleMaterial=cbsoleMaterial.Text;
            if(!string.IsNullOrEmpty(txtallCount.Text.Trim())) m_Sample.allCount = Convert.ToInt32( txtallCount.Text);
            m_Sample.pCount = Convert.ToInt32(txtallCount.Text);
            if(!string.IsNullOrEmpty(txtprintedCount.Text.Trim())) m_Sample.printedCount=Convert.ToInt32( txtprintedCount.Text);
            m_Sample.location=txtLocation.Text;
            if (!string.IsNullOrEmpty(dtopDate.Text.Trim())) m_Sample.opDate = Convert.ToDateTime(dtopDate.Text);
            else m_Sample.opDate = DateTime.Now.Date;
            m_Sample.reMark=txtRemark.Text;
            m_Sample.pMgr= txtpMgr.Text ;
            m_Sample.insock=txtInsock.Text;
            m_Sample.port=txtPort.Text;
            m_Sample.sGroup = cbsGroup.Text;
            m_Sample.sKind = "鞋样";
            m_Sample.bCount = 0;
            m_Sample.jCount = 0;
            m_Sample.oCount = 0;
            m_Sample.sCount = 0;
            m_Sample.srCount = 0;

            db.T_Sample.Add(m_Sample);
            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条鞋样信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }

        //船头板增加
        private void SaveBowAdd()
        {
            m_Sample = new T_Sample();

            if (db.T_Sample.Count() <= 0) m_Sample.xID = 1;
            else m_Sample.xID = db.T_Sample.OrderByDescending(a => a.xID).First().xID + 1;
            m_Sample.productNo=txtBowProductNo.Text;
            if(!string.IsNullOrEmpty(txtBowallCount.Text)) m_Sample.allCount=Convert.ToInt32( txtBowallCount.Text);
            m_Sample.color=txtbowcolor.Text;
            m_Sample.cust=txtBowCust.Text;
            m_Sample.location=txtBowlocation.Text;
            m_Sample.orderNo=txtBoworderNo.Text;
            m_Sample.pCount = Convert.ToInt32(txtBowallCount.Text);
            m_Sample.reMark=txtBowRemark.Text;
            m_Sample.size2=txtBowsize2.Text;
            m_Sample.sName=txtbowsName.Text ;
            m_Sample.brand=cbBowBrand.Text;
            m_Sample.factory=cbBowFactory.Text;
            m_Sample.size1=cbBowsize1.Text;
            m_Sample.yard=cbBowYard.Text;
            if (!string.IsNullOrEmpty(dtbowDate.Text)) m_Sample.opDate = Convert.ToDateTime(dtbowDate.Text);
            else m_Sample.opDate = DateTime.Now.Date;
            m_Sample.custDept=txtfinalCust.Text;
            m_Sample.custProductNo=txtCProductNo.Text;
            m_Sample.contractNo=txtcontractNo.Text;
            m_Sample.sKind = "船头板";

            db.T_Sample.Add(m_Sample);
            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条船头板信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }

        //原版鞋增加
        private void SaveOriginalAdd()
        {
            m_Sample = new T_Sample();

            if (db.T_Sample.Count() <= 0) m_Sample.xID = 1;
            else m_Sample.xID = db.T_Sample.OrderByDescending(a => a.xID).First().xID + 1;
            if(!string.IsNullOrEmpty(txtOallCount.Text)) m_Sample.allCount=Convert .ToInt32( txtOallCount.Text);
            m_Sample.custProductNo=txtOCProductNo.Text;
            m_Sample.cust=txtOCust.Text;
            m_Sample.location=txtOLocation.Text;
            m_Sample.pCount = Convert.ToInt32(txtOallCount.Text);
            m_Sample.productNo=txtOProductNo.Text;
            m_Sample.providerDept=txtOProviderDept.Text;
            m_Sample.reMark=txtORemark.Text;
            m_Sample.brand=cbOBrand.Text;
            m_Sample.prodiver=cbOProvider.Text;
            if (!string.IsNullOrEmpty(dtOopDate.Text)) m_Sample.opDate = Convert.ToDateTime(dtOopDate.Text);
            else m_Sample.opDate = DateTime.Now.Date;
            m_Sample.sKind = "原版鞋";

            db.T_Sample.Add(m_Sample);
            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条原版鞋信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }

        //大底增加
        private void SaveSoleAdd()
        {
            m_Sample = new T_Sample();

            if (db.T_Sample.Count() <= 0) m_Sample.xID = 1;
            else m_Sample.xID = db.T_Sample.OrderByDescending(a => a.xID).First().xID + 1;
            if(!string.IsNullOrEmpty(txtSallCount.Text)) m_Sample.allCount=Convert.ToInt32( txtSallCount.Text);
            m_Sample.factNo=txtSfactNo.Text;
            m_Sample.location=txtSLocation.Text;
            m_Sample.pCount = Convert.ToInt32(txtSallCount.Text);
            if(!string.IsNullOrEmpty(txtSPrice1.Text)) m_Sample.price1=Convert.ToInt32( txtSPrice1.Text);
            if(!string.IsNullOrEmpty(txtSPrice2.Text)) m_Sample.price2=Convert.ToInt32( txtSPrice2.Text);
            if(!string.IsNullOrEmpty(txtSPrice3.Text)) m_Sample.price3=Convert.ToInt32( txtSPrice3.Text);
            if(!string.IsNullOrEmpty(txtSPrice4.Text)) m_Sample.price4=Convert.ToInt32( txtSPrice4.Text);
            m_Sample.productNo=txtSProductNo.Text;
            m_Sample.reMark=txtSRemark.Text;
            m_Sample.size2=txtSSize2.Text;
            m_Sample.soleNo=txtSSoleNo.Text;
            m_Sample.sType=txtSSType.Text;
            m_Sample.yard=txtSYard.Text;
            m_Sample.yard1=txtSYard1.Text;
            m_Sample.yard2=txtSYard2.Text;
            m_Sample.yard3=txtSYard3.Text;
            m_Sample.yard4=txtSYard4.Text;
            m_Sample.factory=cbSFactory.Text;
            m_Sample.soleMaterial=cbSSoleMaterial.Text;
            if (!string.IsNullOrEmpty(dtSDate.Text)) m_Sample.opDate = Convert.ToDateTime(dtSDate.Text);
            else m_Sample.opDate = DateTime.Now.Date;
            if (ckSbCanPrint.Checked == true) m_Sample.bCanPrint = true;
            m_Sample.sKind = "大底";

            db.T_Sample.Add(m_Sample);
            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条大底信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }


        //鞋样修改
        private void SaveModify()
        {
            if (m_Sample.xID <= 0) return;

            m_Sample = db.T_Sample.Where(a => a.xID == m_Sample.xID).First();

            m_Sample.colorCode = txtColorCode.Text;
            m_Sample.sName = txtShoeName.Text;
            m_Sample.color = txtShoeColor.Text;
            m_Sample.yard = cbYard.Text;
            m_Sample.size1 = cbShoesize1.Text;
            m_Sample.size2 = txtShoesize2.Text;
            m_Sample.xc = txtXc.Text;
            m_Sample.yard1 = cbYard1.Text;
            m_Sample.yard2 = cbYard2.Text;
            m_Sample.yard3 = cbYard3.Text;
            m_Sample.yard4 = cbYard4.Text;
            m_Sample.packing = cbPacking.Text;
            m_Sample.InsoleBoard = txtInsoleBoard.Text;
            m_Sample.ch1 = cbch1.Text;
            m_Sample.ch2 = cbch2.Text;
            m_Sample.ch3 = cbch3.Text;
            m_Sample.chValue1 = txtchValue1.Text;
            m_Sample.chValue2 = txtchValue2.Text;
            m_Sample.chValue3 = txtchValue3.Text;
            m_Sample.productNo = txtShoeProductNo.Text;
            m_Sample.cust = cbCust.Text;
            m_Sample.brand = cbBrand.Text;
            m_Sample.custDept = cbCustDept.Text;
            m_Sample.orderNo = txtOrderNo.Text;
            m_Sample.custProductNo = txtcustProductNo.Text;
            m_Sample.buyer = cbBuyer.Text;
            m_Sample.factory = cbFactory.Text;
            m_Sample.factNo = txtFactNo.Text;
            m_Sample.xtNo = txtXtNo.Text;
            m_Sample.SiMo = cbSiMo.Text;
            m_Sample.designNo = txtDesignNo.Text;
            if (!string.IsNullOrEmpty(txtPrice1.Text.Trim())) m_Sample.price1 = Convert.ToInt32(txtPrice1.Text);
            if (!string.IsNullOrEmpty(txtPrice2.Text.Trim())) m_Sample.price2 = Convert.ToInt32(txtPrice2.Text);
            if (!string.IsNullOrEmpty(txtPrice3.Text.Trim())) m_Sample.price3 = Convert.ToInt32(txtPrice3.Text);
            if (!string.IsNullOrEmpty(txtPrice4.Text.Trim())) m_Sample.price4 = Convert.ToInt32(txtPrice4.Text);
            if (!string.IsNullOrEmpty(txtdPrice1.Text.Trim())) m_Sample.dPrice1 = Convert.ToInt32(txtdPrice1.Text);
            if (!string.IsNullOrEmpty(txtdPrice2.Text.Trim())) m_Sample.dPrice2 = Convert.ToInt32(txtdPrice2.Text);
            if (!string.IsNullOrEmpty(txtdPrice3.Text.Trim())) m_Sample.dPrice3 = Convert.ToInt32(txtdPrice3.Text);
            if (!string.IsNullOrEmpty(txtdPrice4.Text.Trim())) m_Sample.dPrice4 = Convert.ToInt32(txtdPrice4.Text);
            m_Sample.Counter = txtCounter.Text;

            if (ckbCanPrint.Checked) m_Sample.bCanPrint = true;
            if (ckIBS.Checked) m_Sample.IBS = "是";
            if (ckPML.Checked) m_Sample.PML = "是";
            if (ckPT3.Checked) m_Sample.PT3 = "是";

            m_Sample.property = cbProperty.Text;
            m_Sample.SampleNo = txtSampleNo.Text;
            m_Sample.seasonType = txtSeason.Text;
            m_Sample.bmStruct = txtbmStruct.Text;
            m_Sample.bmMaterial = txtbmMaterial.Text;
            m_Sample.lMaterial = cblMaterial.Text;
            m_Sample.SoleFactory = cbSoleFactory.Text;
            m_Sample.soleYard = txtsoleYard.Text;
            m_Sample.newXtNo = txtnewXtNo.Text;
            m_Sample.soleNo = txtsoleNo.Text;
            m_Sample.soleMaterial = cbsoleMaterial.Text;
            if (!string.IsNullOrEmpty(txtallCount.Text.Trim())) m_Sample.allCount = Convert.ToInt32(txtallCount.Text);
            if (!string.IsNullOrEmpty(txtpCount.Text.Trim())) m_Sample.pCount = Convert.ToInt32(txtpCount.Text);
            if (!string.IsNullOrEmpty(txtprintedCount.Text.Trim())) m_Sample.printedCount = Convert.ToInt32(txtprintedCount.Text);
            m_Sample.location = txtLocation.Text;
            if (!string.IsNullOrEmpty(dtopDate.Text.Trim())) m_Sample.opDate = Convert.ToDateTime(dtopDate.Text);
            m_Sample.reMark = txtRemark.Text;
            m_Sample.pMgr = txtpMgr.Text;
            m_Sample.insock = txtInsock.Text;
            m_Sample.port = txtPort.Text;
            m_Sample.sGroup = cbsGroup.Text;

            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条鞋样信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }

        //船头板修改
        private void SaveBowModify()
        {
            if (m_Sample.xID <= 0) return;
            m_Sample = db.T_Sample.Where(a => a.xID == m_Sample.xID).First();

            m_Sample.productNo = txtBowProductNo.Text;
            if (!string.IsNullOrEmpty(txtBowallCount.Text)) m_Sample.allCount = Convert.ToInt32(txtBowallCount.Text);
            m_Sample.color = txtbowcolor.Text;
            m_Sample.cust = txtBowCust.Text;
            m_Sample.location = txtBowlocation.Text;
            m_Sample.orderNo = txtBoworderNo.Text;
            if (!string.IsNullOrEmpty(txtBowpCount.Text)) m_Sample.pCount = Convert.ToInt32(txtBowpCount.Text);
            m_Sample.reMark = txtBowRemark.Text;
            m_Sample.size2 = txtBowsize2.Text;
            m_Sample.sName = txtbowsName.Text;
            m_Sample.brand = cbBowBrand.Text;
            m_Sample.factory = cbBowFactory.Text;
            m_Sample.size1 = cbBowsize1.Text;
            m_Sample.yard = cbBowYard.Text;
            if (!string.IsNullOrEmpty(dtbowDate.Text)) m_Sample.opDate = Convert.ToDateTime(dtbowDate.Text);
            m_Sample.custDept = txtfinalCust.Text;
            m_Sample.custProductNo = txtCProductNo.Text;
            m_Sample.contractNo = txtcontractNo.Text;

            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条船头板信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }

        //原版鞋修改
        private void SaveOriginalModify()
        {
            if (m_Sample.xID <= 0) return;
            m_Sample = db.T_Sample.Where(a => a.xID == m_Sample.xID).First();

            if (!string.IsNullOrEmpty(txtOallCount.Text)) m_Sample.allCount = Convert.ToInt32(txtOallCount.Text);
            m_Sample.custProductNo = txtOCProductNo.Text;
            m_Sample.cust = txtOCust.Text;
            m_Sample.location = txtOLocation.Text;
            if (!string.IsNullOrEmpty(txtOpCount.Text)) m_Sample.pCount = Convert.ToInt32(txtOpCount.Text);
            m_Sample.productNo = txtOProductNo.Text;
            m_Sample.providerDept = txtOProviderDept.Text;
            m_Sample.reMark = txtORemark.Text;
            m_Sample.brand = cbOBrand.Text;
            m_Sample.prodiver = cbOProvider.Text;
            if (!string.IsNullOrEmpty(dtOopDate.Text)) m_Sample.opDate = Convert.ToDateTime(dtOopDate.Text);

            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条原版鞋信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }

        //大底修改 
        private void SaveSoleModify()
        {
            if (m_Sample.xID <= 0) return;
            m_Sample = db.T_Sample.Where(a => a.xID == m_Sample.xID).First();

            if (!string.IsNullOrEmpty(txtSallCount.Text)) m_Sample.allCount = Convert.ToInt32(txtSallCount.Text);
            m_Sample.factNo = txtSfactNo.Text;
            m_Sample.location = txtSLocation.Text;
            if (!string.IsNullOrEmpty(txtSpCount.Text)) m_Sample.pCount = Convert.ToInt32(txtSpCount.Text);
            if (!string.IsNullOrEmpty(txtSPrice1.Text)) m_Sample.price1 = Convert.ToInt32(txtSPrice1.Text);
            if (!string.IsNullOrEmpty(txtSPrice2.Text)) m_Sample.price2 = Convert.ToInt32(txtSPrice2.Text);
            if (!string.IsNullOrEmpty(txtSPrice3.Text)) m_Sample.price3 = Convert.ToInt32(txtSPrice3.Text);
            if (!string.IsNullOrEmpty(txtSPrice4.Text)) m_Sample.price4 = Convert.ToInt32(txtSPrice4.Text);
            m_Sample.productNo = txtSProductNo.Text;
            m_Sample.reMark = txtSRemark.Text;
            m_Sample.size2 = txtSSize2.Text;
            m_Sample.soleNo = txtSSoleNo.Text;
            m_Sample.sType = txtSSType.Text;
            m_Sample.yard = txtSYard.Text;
            m_Sample.yard1 = txtSYard1.Text;
            m_Sample.yard2 = txtSYard2.Text;
            m_Sample.yard3 = txtSYard3.Text;
            m_Sample.yard4 = txtSYard4.Text;
            m_Sample.factory = cbSFactory.Text;
            m_Sample.soleMaterial = cbSSoleMaterial.Text;
            if (!string.IsNullOrEmpty(dtSDate.Text)) m_Sample.opDate = Convert.ToDateTime(dtSDate.Text);
            if (ckSbCanPrint.Checked == true) m_Sample.bCanPrint = true;

            int i = db.SaveChanges();
            Msg.ShowInfo(string.Format("已保存{0}条大底信息。", i));
            this.panList.BringToFront();
            this.btn1.Text = "明细";
            this.IsQuery = true;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            this.panDetail.BringToFront();
            this.btn1.Text = "概要";
            this.IsQuery = false;

            this.bIsAdd = true;
            if (rbShoesSample.Checked)
            {
                this.xID = 0;
                m_Sample = null;
                TxtSampleClear();
            }
            else if (rbBowPlate.Checked)
            {
                this.BowplateProduct = 0;
                m_Sample = null;
                TxtBowplateClear();
            }
            else if (rbOriginalShoe.Checked)
            {
                this.OriginalShoeProductNo = 0;
                m_Sample = null;
                TxtOriginalClear();
            }
            else if (rbSole.Checked)
            {
                this.SoleProductNo = 0;
                m_Sample = null;
                TxtSoleClear();
            }
        }

        private void TxtSampleClear()
        {
            txtColorCode.Text = "";
            txtShoeName.Text = "";
            txtShoeColor.Text = "";
            cbYard.Text = "";
            cbShoesize1.Text = "";
            txtShoesize2.Text = "";
            txtXc.Text = "";
            cbYard1.Text = "";
            cbYard2.Text = "";
            cbYard3.Text = "";
            cbYard4.Text = "";
            cbPacking.Text = "";
            txtInsoleBoard.Text = "";
            cbch1.Text = "";
            cbch2.Text = "";
            cbch3.Text = "";
            txtchValue1.Text = "";
            txtchValue2.Text = "";
            txtchValue3.Text = "";
            txtShoeProductNo.Text = "";
            cbCust.Text = "";
            cbBrand.Text = "";
            cbCustDept.Text = "";
            txtOrderNo.Text = "";
            txtcustProductNo.Text = "";
            cbBuyer.Text = "";
            cbFactory.Text = "";
            txtFactNo.Text = "";
            txtXtNo.Text = "";
            cbSiMo.Text = "";
            txtDesignNo.Text = "";
            txtPrice1.Text = "";
            txtPrice2.Text = "";
            txtPrice3.Text = "";
            txtPrice4.Text = "";
            txtdPrice1.Text = "";
            txtdPrice2.Text = "";
            txtdPrice3.Text = "";
            txtdPrice4.Text = "";
            txtCounter.Text = "";

            ckbCanPrint.Checked = false;
            ckIBS.Checked = false;
            ckPML.Checked = false;
            ckPT3.Checked = false;

            cbProperty.Text = "";
            txtSampleNo.Text = "";
            txtSeason.Text = "";
            txtbmStruct.Text = "";
            txtbmMaterial.Text = "";
            cblMaterial.Text = "";
            cbSoleFactory.Text = "";
            txtsoleYard.Text = "";
            txtnewXtNo.Text = "";
            txtsoleNo.Text = "";
            cbsoleMaterial.Text = "";
            txtallCount.Text = "";
            txtpCount.Text = "";
            txtprintedCount.Text = "";
            txtLocation.Text = "";
            dtopDate.Text = "";
            txtRemark.Text = "";
            txtpMgr.Text = "";
            txtInsock.Text = "";
            txtPort.Text = "";
            cbsGroup.Text = "";
        }

        private void TxtBowplateClear()
        {
            Helper.TxtClear(txtBowallCount);
            Helper.TxtClear(txtbowcolor);
            Helper.TxtClear(txtBowCust);
            Helper.TxtClear(txtBowlocation);
            Helper.TxtClear(txtBoworderNo);
            Helper.TxtClear(txtBowpCount);
            Helper.TxtClear(txtBowProductNo);
            Helper.TxtClear(txtBowRemark);
            Helper.TxtClear(txtBowsize2);
            Helper.TxtClear(txtbowsName);
            Helper.TxtClear(txtcontractNo);
            Helper.TxtClear(txtCProductNo);
            Helper.TxtClear(txtfinalCust);
            Helper.CBClear(cbBowBrand);
            Helper.CBClear(cbBowFactory);
            Helper.CBClear(cbBowsize1);
            Helper.CBClear(cbBowYard);
            dtbowDate.Text = string.Empty;

        }

        private void TxtOriginalClear()
        {
            Helper.TxtClear(txtOallCount);
            Helper.TxtClear(txtOCProductNo);
            Helper.TxtClear(txtOCust);
            Helper.TxtClear(txtOLocation);
            Helper.TxtClear(txtOpCount);
            Helper.TxtClear(txtOProductNo);
            Helper.TxtClear(txtOProviderDept);
            Helper.TxtClear(txtORemark);
            Helper.CBClear(cbOBrand);
            Helper.CBClear(cbOProvider);
            dtOopDate.Text = "";
        }

        private void TxtSoleClear()
        {
            Helper.TxtClear(txtSallCount);
            Helper.TxtClear(txtSfactNo);
            Helper.TxtClear(txtSLocation);
            Helper.TxtClear(txtSpCount);
            Helper.TxtClear(txtSPrice1);
            Helper.TxtClear(txtSPrice2);
            Helper.TxtClear(txtSPrice3);
            Helper.TxtClear(txtSPrice4);
            Helper.TxtClear(txtSProductNo);
            Helper.TxtClear(txtSRemark);
            Helper.TxtClear(txtSSize2);
            Helper.TxtClear(txtSSoleNo);
            Helper.TxtClear(txtSSType);
            Helper.TxtClear(txtSYard);
            Helper.TxtClear(txtSYard1);
            Helper.TxtClear(txtSYard2);
            Helper.TxtClear(txtSYard3);
            Helper.TxtClear(txtSYard4);
            Helper.CBClear(cbSFactory);
            Helper.CBClear(cbSSoleMaterial);
            dtSDate.Text = "";
            ckSbCanPrint.Checked = false;
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            btn1_Click(null, null);
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (rbShoesSample.Checked)
            {
                if (Helper.TxtNotNull(txtShoeColor) &&
                Helper.CBNotNull(cbShoesize1) &&
                Helper.TxtNotNull(txtShoesize2) &&
                Helper.TxtNotNull(txtXc) &&
                Helper.TxtNotNull(txtShoeProductNo) &&
                Helper.CBNotNull(cbBrand) &&
                Helper.CBNotNull(cbFactory) &&
                Helper.TxtNotNull(txtXtNo) &&
                Helper.TxtNotNull(txtDesignNo) &&
                Helper.CBNotNull(cbProperty) &&
                Helper.TxtNotNull(txtSampleNo) &&
                txtbmMaterial.Text!=string.Empty &&
                Helper.CBNotNull(cbSoleFactory) &&
                Helper.TxtNotNull(txtsoleYard) &&
                Helper.TxtNotNull(txtnewXtNo) &&
                Helper.TxtNotNull(txtsoleNo) &&
                Helper.CBNotNull(cbsoleMaterial) &&
                Helper.TxtNotNull(txtallCount)&&
                Helper.CBNotNull(cbsGroup))
                {
                    if (Msg.ShowWarning("您确信保存鞋样信息吗？") == System.Windows.Forms.DialogResult.Yes)
                    {
                        if (m_Sample == null)
                        {
                            SaveAdd();
                            gv1DataSource();
                        }
                        else
                        {
                            SaveModify();
                            gv1DataSource();
                        }
                    }
                }
                else
                {
                    Msg.ShowError("请填写必填项！");
                }
            }
            else if (rbBowPlate.Checked)
            {
                if (Helper.TxtNotNull(txtcontractNo) &&
                Helper.TxtNotNull(txtBowProductNo) &&
                Helper.TxtNotNull(txtCProductNo) &&
                Helper.TxtNotNull(txtBowallCount) &&
                Helper.CBNotNull(cbBowBrand) &&
                Helper.CBNotNull(cbBowFactory))
                {
                    if (Msg.ShowWarning("您确信保存船头板信息吗？") == System.Windows.Forms.DialogResult.Yes)
                    {
                        if (m_Sample == null)
                        {
                            SaveBowAdd();
                            gv1DataSource();
                        }
                        else
                        {
                            SaveBowModify();
                            gv1DataSource();
                        }
                    }
                }
                else
                {
                    Msg.ShowError("请填写必填项！");
                }
            }
            else if (rbOriginalShoe.Checked)
            {
                if (Helper.TxtNotNull(txtOallCount) &&
                    Helper.TxtNotNull(txtOProductNo) &&
                    Helper.CBNotNull(cbOBrand))
                {
                    if (Msg.ShowWarning("您确信保存原版鞋信息吗？") == System.Windows.Forms.DialogResult.Yes)
                    {
                        if (m_Sample == null)
                        {
                            SaveOriginalAdd();
                            gv1DataSource();
                        }
                        else
                        {
                            SaveOriginalModify();
                            gv1DataSource();
                        }
                    }
                }
                else
                {
                    Msg.ShowError("请填写必填项！");
                }
            }
            else if (rbSole.Checked)
            {
                if (Helper.TxtNotNull(txtSProductNo) &&
                    Helper.TxtNotNull(txtSallCount) &&
                    Helper.CBNotNull(cbSFactory))
                {
                    if (Msg.ShowWarning("您确信保存大底信息吗？") == System.Windows.Forms.DialogResult.Yes)
                    {
                        if (m_Sample == null)
                        {
                            SaveSoleAdd();
                            gv1DataSource();
                        }
                        else
                        {
                            SaveSoleModify();
                            gv1DataSource();
                        }
                    }
                }
                else
                {
                    Msg.ShowError("请输入必填项！");
                }
            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (Msg.ShowWarning("您确信删除信息吗？") == System.Windows.Forms.DialogResult.Yes)
            {
                gvID();
                if (m_xID == 0)
                {
                    Msg.ShowError("请选择一条记录！");
                    return;
                }
                T_Sample sample = db.T_Sample.First(a => a.xID == m_xID);
                db.T_Sample.Remove(sample);
                int i = db.SaveChanges();
                Msg.ShowInfo(string.Format("已删除{0}条鞋样信息。", i));
                gv1DataSource();
                //if (rbShoesSample.Checked)
                //{
                //    if (m_xID == 0)
                //    {
                //        Msg.ShowError("请选择一条记录！");
                //        return;
                //    }
                //    T_Sample sample = db.T_Sample.First(a => a.xID == m_xID);
                //    db.T_Sample.Remove(sample);
                //    int i = db.SaveChanges();
                //    Msg.ShowInfo(string.Format("已删除{0}条鞋样信息。", i));
                //    gv1DataSource();
                //}
                //else if (rbBowPlate.Checked)
                //{
                //    if (m_bowplateProductNo == "")
                //    {
                //        Msg.ShowError("请选择一条记录！");
                //        return;
                //    }
                //    T_Sample sample = db.T_Sample.First(a => a.productNo == m_bowplateProductNo);
                //    db.T_Sample.Remove(sample);
                //    int i = db.SaveChanges();
                //    Msg.ShowInfo(string.Format("已删除{0}条船头板信息。", i));
                //    gv1DataSource();
                //}
                //else if (rbOriginalShoe.Checked)
                //{
                //    if (m_originalshoeProductNo == "")
                //    {
                //        Msg.ShowError("请选择一条记录！");
                //        return;
                //    }
                //    T_Sample sample = db.T_Sample.First(a => a.productNo == m_originalshoeProductNo);
                //    db.T_Sample.Remove(sample);
                //    int i = db.SaveChanges();
                //    Msg.ShowError(string.Format("已删除{0}条原版鞋信息。", i));
                //    gv1DataSource();
                //}
                //else if (rbSole.Checked)
                //{
                //    if (m_soleProductNo == "")
                //    {
                //        Msg.ShowError("请选择一条记录！");
                //        return;
                //    }
                //    T_Sample sample = db.T_Sample.First(a => a.productNo == m_soleProductNo);
                //    db.T_Sample.Remove(sample);
                //    int i = db.SaveChanges();
                //    Msg.ShowError(string.Format("已删除{0}条大底信息。", i));
                //    gv1DataSource();
                //}
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (Msg.ShowWarning("尚未保存，您确定要取消吗？") == System.Windows.Forms.DialogResult.Yes)
            {
                this.panList.BringToFront();
                this.btn1.Text = "明细";
                this.IsQuery = true;
            }
        }

        private void gv1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.xID = Convert.ToInt32(gv1.Rows[e.RowIndex].Cells["colxID"].Value.ToString());
                this.panDetail.BringToFront();
                cTabs1.SelectTab(tabShoeSample);
                this.btn1.Text = "概要";
                this.IsQuery = false;
            }
            catch
            {
                Msg.ShowError("请选择表里的数据！");
            }
        }

        private void gv2_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.BowplateProduct = Convert.ToInt32(gv2.Rows[e.RowIndex].Cells["colBxID"].Value.ToString());
                this.panDetail.BringToFront();
                cTabs1.SelectTab(tabBowPlate);
                this.btn1.Text = "概要";
                this.IsQuery = false;
            }
            catch
            {
                Msg.ShowError("请选择表里的数据！");
            }
        }

        private void gv3_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.OriginalShoeProductNo = Convert.ToInt32(gv3.Rows[e.RowIndex].Cells["colOxID"].Value.ToString());
                this.panDetail.BringToFront();
                cTabs1.SelectTab(tabOriginShoe);
                this.btn1.Text = "概要";
                this.IsQuery = false;
            }
            catch
            {
                Msg.ShowError("请选择表里的数据！");
            }
        }

        private void gv4_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.SoleProductNo = Convert.ToInt32(gv4.Rows[e.RowIndex].Cells["colSxID"].Value.ToString());
                this.panDetail.BringToFront();
                cTabs1.SelectTab(tabSole);
                this.btn1.Text = "概要";
                this.IsQuery = false;
            }
            catch
            {
                Msg.ShowError("请选择表里的数据！");
            }
        }

        private void btnSelect_Click(object sender, EventArgs e)
        {
            if (rbShoesSample.Checked)
            {
                var list = db.T_Sample.Where(a => 1 == 1);

                if (!string.IsNullOrEmpty(txtSelProductNo.Text))
                {
                    list.Where(a => a.productNo == txtSelProductNo.Text);
                }
                if (!string.IsNullOrEmpty(txtSelDate.Text))
                {
                    DateTime dt = Convert.ToDateTime(txtSelDate.Text);
                    list.Where(a => a.opDate == dt);
                }
                if (!string.IsNullOrEmpty(txtSelLocation.Text))
                {
                    list.Where(a => a.location == txtSelLocation.Text);
                }
                if (!string.IsNullOrEmpty(txtSelBrand.Text))
                {
                    list.Where(a => a.brand == txtSelBrand.Text);
                }
                if (!string.IsNullOrEmpty(txtSelFactory.Text))
                {
                    list.Where(a => a.factory == txtSelFactory.Text);
                }
                if (!string.IsNullOrEmpty(txtSelSoleNo.Text))
                {
                    list.Where(a => a.factNo == txtSelSoleNo.Text);
                }
                if (!string.IsNullOrEmpty(txtSelOrder.Text))
                {
                    list.Where(a => a.orderNo == txtSelOrder.Text);
                }
                
                bs1.DataSource = list.Where(a=>a.sKind=="鞋样").ToList();

                if (bs1.Count <= 0)
                {
                    Msg.ShowWarning("没有满足条件的数据，请重新设置条件！");
                    return;
                }
                gv1.DataSource = bs1;
                bNav.BindingSource = bs1;
                
            }
            else if (rbBowPlate.Checked)
            {
                var list = db.T_Sample.Where(a => 1 == 1);

                if (!string.IsNullOrEmpty(txtSelProductNo.Text))
                {
                    list.Where(a => a.productNo == txtSelProductNo.Text);
                }
                if (!string.IsNullOrEmpty(txtSelDate.Text))
                {
                    DateTime dt = Convert.ToDateTime(txtSelDate.Text);
                    list.Where(a => a.opDate == dt);
                }
                if (!string.IsNullOrEmpty(txtSelLocation.Text))
                {
                    list.Where(a => a.location == txtSelLocation.Text);
                }
                if (!string.IsNullOrEmpty(txtSelBrand.Text))
                {
                    list.Where(a => a.brand == txtSelBrand.Text);
                }
                if (!string.IsNullOrEmpty(txtSelFactory.Text))
                {
                    list.Where(a => a.factory == txtSelFactory.Text);
                }
                if (!string.IsNullOrEmpty(txtSelSoleNo.Text))
                {
                    list.Where(a => a.factNo == txtSelSoleNo.Text);
                }
                if (!string.IsNullOrEmpty(txtSelOrder.Text))
                {
                    list.Where(a => a.orderNo == txtSelOrder.Text);
                }
                bs2.DataSource = list.Where(a => a.sKind == "船头板").ToList();
                if (bs2.Count <= 0)
                {
                    Msg.ShowWarning("没有满足条件的数据，请重新设置条件！");
                    return;
                }
                gv2.DataSource = bs2;
                bNav.BindingSource = bs2;
            }
            else if (rbOriginalShoe.Checked)
            {

                var list = db.T_Sample.Where(a => 1 == 1);

                if (!string.IsNullOrEmpty(txtSelProductNo.Text))
                {
                    list.Where(a => a.productNo == txtSelProductNo.Text);
                }
                if (!string.IsNullOrEmpty(txtSelDate.Text))
                {
                    DateTime dt = Convert.ToDateTime(txtSelDate.Text);
                    list.Where(a => a.opDate == dt);
                }
                if (!string.IsNullOrEmpty(txtSelLocation.Text))
                {
                    list.Where(a => a.location == txtSelLocation.Text);
                }
                if (!string.IsNullOrEmpty(txtSelBrand.Text))
                {
                    list.Where(a => a.brand == txtSelBrand.Text);
                }
                if (!string.IsNullOrEmpty(txtSelFactory.Text))
                {
                    list.Where(a => a.factory == txtSelFactory.Text);
                }
                if (!string.IsNullOrEmpty(txtSelSoleNo.Text))
                {
                    list.Where(a => a.factNo == txtSelSoleNo.Text);
                }
                if (!string.IsNullOrEmpty(txtSelOrder.Text))
                {
                    list.Where(a => a.orderNo == txtSelOrder.Text);
                }
                bs3.DataSource = list.Where(a => a.sKind == "原版鞋").ToList();
                if (bs3.Count <= 0)
                {
                    Msg.ShowWarning("没有满足条件的数据，请重新设置条件！");
                    return;
                }
                gv3.DataSource = bs3;
                bNav.BindingSource = bs3;
            }
            else if (rbSole.Checked)
            {
                var list = db.T_Sample.Where(a => 1 == 1);

                if (!string.IsNullOrEmpty(txtSelProductNo.Text))
                {
                    list.Where(a => a.productNo == txtSelProductNo.Text);
                }
                if (!string.IsNullOrEmpty(txtSelDate.Text))
                {
                    DateTime dt = Convert.ToDateTime(txtSelDate.Text);
                    list.Where(a => a.opDate == dt);
                }
                if (!string.IsNullOrEmpty(txtSelLocation.Text))
                {
                    list.Where(a => a.location == txtSelLocation.Text);
                }
                if (!string.IsNullOrEmpty(txtSelBrand.Text))
                {
                    list.Where(a => a.brand == txtSelBrand.Text);
                }
                if (!string.IsNullOrEmpty(txtSelFactory.Text))
                {
                    list.Where(a => a.factory == txtSelFactory.Text);
                }
                if (!string.IsNullOrEmpty(txtSelSoleNo.Text))
                {
                    list.Where(a => a.factNo == txtSelSoleNo.Text);
                }
                if (!string.IsNullOrEmpty(txtSelOrder.Text))
                {
                    list.Where(a => a.orderNo == txtSelOrder.Text);
                }
                bs4.DataSource = list.Where(a => a.sKind == "大底").ToList();
                if (bs4.Count <= 0)
                {
                    Msg.ShowWarning("没有满足条件的数据，请重新设置条件！");
                    return;
                }
                gv4.DataSource = bs4;
                bNav.BindingSource = bs4;
            }

        }

        private void frmSample_Load(object sender, EventArgs e)
        {
            GetBaseInfo();
            gv1DataSource();
            this.panList.BringToFront();

            gv1.Visible = true;
            gv2.Visible = false;
            gv3.Visible = false;
            gv4.Visible = false;

            rbShoesSample.Checked = true;

            //this.gv1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中
            //this.gv2.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中
            //this.gv3.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中
            //this.gv4.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//设置为整行被选中

            if (Startup.GetApp().CurrentUser != null)
            {
                //tslb1.Text = "制单人：" + Startup.GetApp().CurrentUser.username;
                //tslb2.Text = "制单日期：" + DateTime.Now.ToLocalTime();
            }
        }

        private void btnAllChoose_Click(object sender, EventArgs e)
        {
            if (gv1.RowCount > 0)
            {
                for (int i = 0; i < gv1.RowCount; i++)
                {
                    if (bool.Parse(this.gv1.Rows[i].Cells[0].EditedFormattedValue.ToString()) == true)
                    {
                        continue;
                    }
                    else
                    {
                        this.gv1.Rows[i].Cells[0].Value = true;

                        //xID.Add(Convert.ToInt32(gv1.Rows[i].Cells["colxID"].Value.ToString()));
                    }
                }
            }
        }

        private void btnNoChoose_Click(object sender, EventArgs e)
        {
            if (gv1.RowCount > 0)
            {
                for (int i = 0; i < gv1.RowCount; i++)
                {
                    if (bool.Parse(this.gv1.Rows[i].Cells[0].EditedFormattedValue.ToString()) == false)
                    {
                        this.gv1.Rows[i].Cells[0].Value = false;
                    }
                    else
                    {
                        this.gv1.Rows[i].Cells[0].Value = true;

                        //xID.Add(Convert.ToInt32(gv1.Rows[i].Cells["colxID"].Value.ToString()));

                    }
                }
            }
        }

        private void btnmemuCancel_Click(object sender, EventArgs e)
        {
            if (gv1.RowCount > 0)
            {
                for (int i = 0; i < gv1.RowCount; i++)
                {
                    if (bool.Parse(this.gv1.Rows[i].Cells[0].EditedFormattedValue.ToString()) == false)
                    {
                        continue;
                    }
                    else
                    {
                        this.gv1.Rows[i].Cells[0].Value = false;

                        //xID.Add(Convert.ToInt32(gv1.Rows[i].Cells["colxID"].Value.ToString()));

                    }
                }
            }
        }
    }


}
